﻿Imports System.Data
Imports PadovadoAPI

Partial Class TabWeek
    Inherits System.Web.UI.UserControl

   


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
        CaricaRepeater()

    End Sub


    Public Sub CaricaRepeater()
        'Dim diz As New Dizionario
        Dim sql As String = ""
        ' Try

        Dim ds As New DataSet
        Dim FK_target As New Integer
        Dim dbConnector As New DBObject

        If (Not String.IsNullOrEmpty(Request.QueryString("FK_Target"))) Then
            FK_target = Request.QueryString("FK_Target")
        End If
        Dim rptEventis As New List(Of Repeater)
        rptEventis.Add(RptEventi1)
        rptEventis.Add(RptEventi2)
        rptEventis.Add(RptEventi3)
        rptEventis.Add(RptEventi4)
        rptEventis.Add(RptEventi5)
        rptEventis.Add(RptEventi6)
        rptEventis.Add(RptEventi7)
        For i As Integer = 0 To 6
            sql = "SELECT isnull(I.Comune,'') + ' ' +  E.Nome as NomeEvento, E.Descrizione as DescrizioneEvento, " & _
                    "E.imgEvento as ImgEvento," & _
                    "  isnull(I.Strada,'') + ' ' + isnull(I.Civico,'') + ' ' + isnull(I.Comune,'') + ' ' + isnull(I.Presso,'') as Indirizzo, " & _
                    " ROW_NUMBER() OVER(ORDER BY E.PK_EventoPeriodico) AS 'RowNumber'" & _
                   " FROM EventoPeriodico E " & _
                   " LEFT OUTER JOIN Indirizzo I ON I.PK_Indirizzo = FK_Indirizzo " & _
                     " WHERE E.Deleted= 0 AND (E.giorno = " & i + 1 & " or E.Giorno = 8)"
            ' DBObject.WriteLog(sql)
            ' Throw New Exception(sql)
           
            'Throw New Exception(sql)
            ds = dbConnector.FillDS(sql, Nothing, 1)

            '<%#DataBinder.Eval(Container.DataItem, "ImageTargetId")%>'
            If Not IsNothing(ds) AndAlso ds.Tables.Count > 0 Then
                ds.Tables(0).Columns.Add("ItemTemplateId")
                ds.Tables(0).Columns.Add("ImageApriId")
                For Each dr As DataRow In ds.Tables(0).Rows
                    dr("ItemTemplateId") = "ItemTemplate_" & i & "_" & dr("RowNumber")
                    dr("ImageApriId") = "ImageApri_" & i & "_" & dr("RowNumber")
                Next
                ' Throw New Exception(ds.Tables.Count)
                rptEventis(i).DataSource = ds
                rptEventis(i).DataBind()
            End If
        Next

        ' Catch ex As Exception
        '  Throw New Exception(sql)
        '  End Try
    End Sub

End Class
